/**
 * BrandBigData.com Inc.
 * Copyright (c) 2016 All Rights Reserved.
 */
package com.qibao.toolkit.protocol.service;

import com.google.common.eventbus.EventBus;
import com.qibao.toolkit.util.JsonUtils;
import com.qibao.toolkit.web.ResponseModel;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.fluent.Response;
import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * @author xumin
 * @version $Id:DataShareCallbackService.java, v0.1 2017/12/19 12:53 xumin
// */
//@Component
//public class DataShareCallbackService_bak {
//    private static final Logger logger = LoggerFactory.getLogger(DataShareCallbackService_bak.class);
//    private static final String TOPIC = "DataServiceCallback";
//    private static final String CONSUMER_GROUP = "toolkit-dataservice";
//    @Value("${datashare.eventbus.address:}")
//    private String serverAddress;
//    @Value("${server.port:8080}")
//    private Integer serverPort;
//
//    @PostConstruct
//    public void init() {
//        if (StringUtils.isEmpty(serverAddress)) {
//            logger.warn("没有配置datashare.eventbus.address，跳过DataShareCallbackService初始化");
//            return;
//        }
//        EventBus eventBus = new EventBus(serverAddress);
//        eventBus.subscribe(TOPIC, CONSUMER_GROUP, event -> {
//            logger.info("收到datashare中转的回调: {}", event.toString());
//            String content = event.getContent();
//            try {
//                Response response = Request.Post("http://localhost:" + serverPort + "/dataService/callback").bodyString(content, ContentType.APPLICATION_JSON).execute();
//                String result = response.returnContent().asString();
//                ResponseModel responseModel = JsonUtils.readValue(result, ResponseModel.class);
//                if (responseModel.getStatus() != 200) {
//                    logger.error("调用数据服务回调接口出错：" + responseModel.getMessage());
//                }
//            } catch (Exception e) {
//                logger.error("调用数据服务回调接口失败:" + e.getMessage(), e);
//            }
//        });
//
//    }
//
//}
